home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / os2 / memsz313.zip / SOURCE.ZIP / ITEMS.CPP < prev    next >
Text File  |  1996-04-02  |  29KB  |  969 lines

  1. /****************************************************************** ITEMS.CPP
  2.  *                                                                          *
  3.  *                     Display Item Class Functions                         *
  4.  *                                                                          *
  5.  ****************************************************************************/
  6.  
  7. #define INCL_BASE
  8. #define INCL_PM
  9. #include <os2.h>
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include <time.h>
  15.  
  16. #include "Config.h"
  17. #include "Debug.h"
  18. #include "DQPS.h"
  19. #include "Support.h"
  20. #include "ReString.h"
  21.  
  22. #include "Items.h"
  23.  
  24. static void FormatValue ( long Value, char Text[], COUNTRYINFO &CountryInfo, int ShowK=SHOWK_ABOVE512, int Scale=1 ) {
  25.  
  26.    switch ( ShowK ) {
  27.       case SHOWK_NEVER:
  28.          sprintf ( Text, "%lu", Value*Scale ) ;
  29.          break;
  30.       case SHOWK_ALWAYS:
  31.          sprintf ( Text, "%lu", (Value+(512/Scale))/(1024/Scale) ) ;
  32.          break;
  33.       case SHOWK_ABOVE512:
  34.       default:
  35.          if ( Value < 0x80000/Scale )
  36.             sprintf ( Text, "%lu", Value*Scale ) ;
  37.          else
  38.             sprintf ( Text, "%lu", (Value+(512/Scale))/(1024/Scale) ) ;
  39.          break;
  40.    } /* endswitch */
  41.  
  42.    char Work[100] ;
  43.    char *p1 = Text ;
  44.    char *p2 = Work ;
  45.    while ( *p1 ) {
  46.       *p2 = *p1 ;
  47.       p1 ++ ;
  48.       p2 ++ ;
  49.       if ( *p1 ) {
  50.          if ( strlen(p1) % 3 == 0 ) {
  51.             *p2 = CountryInfo.szThousandsSeparator [0] ;
  52.             p2 ++ ;
  53.          } /* endif */
  54.       } /* endif */
  55.    } /* endwhile */
  56.    *p2 = 0 ;
  57.    strcpy ( Text, Work ) ;
  58.  
  59.    p2 = Text + strlen(Text) ;
  60.    *(p2+1) = 0 ;
  61.    switch ( ShowK ) {
  62.       case SHOWK_NEVER:
  63.          *p2 = ' ' ;
  64.          break;
  65.       case SHOWK_ALWAYS:
  66.          *p2 = 'K' ;
  67.          break;
  68.       case SHOWK_ABOVE512:
  69.       default:
  70.          if ( Value < 0x80000/Scale )
  71.             *p2 = ' ' ;
  72.          else
  73.             *p2 = 'K' ;
  74.          break;
  75.    } /* endswitch */
  76. }
  77.  
  78.  
  79. void Item::FormatLine ( char *Buffer, int MaxWidth ) {
  80.  
  81.    // Get the left and right texts for the line.
  82.    char Label[100], Text[100] ;
  83.    FormatText ( Label, Text, QueryValue() ) ;
  84.  
  85.    // Format the line.
  86.    strcat ( Buffer, Label ) ;
  87.    sprintf ( Buffer+strlen(Buffer), "%*s", MaxWidth-strlen(Label)-strlen(Text), "" ) ;
  88.    strcat ( Buffer, Text ) ;
  89.    strcat ( Buffer, "\r\n" ) ;
  90. }
  91.  
  92.  
  93. void Item::DdeUpdate ( char *Text ) {
  94.  
  95.    int Format, Size ; PVOID Data ;
  96.    pDdeItem->Query ( Format, Data, Size ) ;
  97.  
  98.    int NewSize = strlen(Text) + 1 ;
  99.    if ( Data && memcmp ( Text, Data, NewSize ) )
  100.       pDdeItem->Update ( DDEFMT_TEXT, Text, NewSize ) ;
  101. }
  102.  
  103.  
  104. void Item::Paint ( HPS hPS, RECTL &Rectangle,
  105.    COLOR TextColor, COLOR BackColor, 
  106.    char *Label, char *Text, ULONG NewValue ) {
  107.  
  108.    WinDrawText ( hPS, strlen(Text), PSZ(Text), &Rectangle,
  109.       TextColor, BackColor, DT_RIGHT | DT_BOTTOM | DT_ERASERECT ) ;
  110.  
  111.    WinDrawText ( hPS, strlen(Label), PSZ(Label), &Rectangle,
  112.       TextColor, BackColor, DT_LEFT | DT_BOTTOM ) ;
  113.  
  114.    Value = NewValue ;
  115. }
  116.  
  117.  
  118. int Clock::Measure ( HPS hPS, RECTL &Rectangle ) {
  119.    int Result ;
  120.    char Text [100] ;
  121.    if ( CountryInfo.fsDateFmt != DATEFMT_YY_MM_DD ) {
  122.       Result = sprintf ( Text, " MMM, MM-DD HH:MM%s%s ", ShowSeconds?":SS":"", CountryInfo.fsTimeFmt?"":"xx" ) ;
  123.    } else {
  124.       Result = sprintf ( Text, " MM-DD MMM HH:MM%s%s ", ShowSeconds?":SS":"", CountryInfo.fsTimeFmt?"":"xx" ) ;
  125.    } /* endif */
  126.    WinQueryWindowRect ( HWND_DESKTOP, &Rectangle ) ;
  127.    WinDrawText ( hPS, strlen(Text), PSZ(Text), &Rectangle, 0, 0, DT_LEFT | DT_BOTTOM | DT_QUERYEXTENT ) ;
  128.    return ( Result ) ;
  129. }
  130.  
  131. struct Date_Time {
  132.    unsigned Weekday : 3 ;
  133.    unsigned Month : 4 ;
  134.    unsigned Day : 5 ;
  135.    unsigned Hours : 5 ;
  136.    unsigned Minutes : 6 ;
  137.    unsigned Seconds : 6 ;
  138. } ;
  139.  
  140. ULONG Clock::NewValue ( void ) {
  141.  
  142.   DATETIME DateTime ;
  143.   DosGetDateTime ( &DateTime ) ;
  144.  
  145.   struct Date_Time Dttm = { 
  146.      DateTime.weekday, 
  147.      DateTime.month, 
  148.      DateTime.day, 
  149.      DateTime.hours, 
  150.      DateTime.minutes, 
  151.      0 
  152.   } ;
  153.  
  154.   if ( ShowSeconds ) 
  155.      Dttm.Seconds = DateTime.seconds ;
  156.  
  157.   ULONG Time = * ( (PULONG) &Dttm ) ;
  158.  
  159.   return ( Time ) ;
  160. }
  161.  
  162.  
  163. void Clock::FormatText ( char *Label, char *Text, ULONG Time ) {
  164.  
  165.    strcpy ( Label, CurrentLabel ) ;
  166.  
  167.    struct Date_Time Dttm = * ( (struct Date_Time*) &Time ) ;
  168.    ULONG Dow    = Dttm.Weekday ;
  169.    ULONG Month  = Dttm.Month ;
  170.    ULONG Day    = Dttm.Day ;
  171.    ULONG Hour   = Dttm.Hours ;
  172.    ULONG Minute = Dttm.Minutes ;
  173.    ULONG Second = Dttm.Seconds ;
  174.  
  175.    switch ( CountryInfo.fsDateFmt ) {
  176.  
  177.       case DATEFMT_DD_MM_YY:
  178.          sprintf ( Text, "%0.*s, %02lu%s%02lu ",
  179.             strlen(PCHAR(*DaysOfWeek))/7, PSZ(*DaysOfWeek) + Dow*(strlen(PCHAR(*DaysOfWeek))/7),
  180.             Day, CountryInfo.szDateSeparator, Month ) ;
  181.          break ;
  182.  
  183.       case DATEFMT_YY_MM_DD:
  184.          sprintf ( Text, "%02lu%s%02lu %0.*s ",
  185.             Month, CountryInfo.szDateSeparator, Day,
  186.             strlen(PCHAR(*DaysOfWeek))/7, PSZ(*DaysOfWeek) + Dow*(strlen(PCHAR(*DaysOfWeek))/7) ) ;
  187.          break ;
  188.  
  189.       case DATEFMT_MM_DD_YY:
  190.       default:
  191.          sprintf ( Text, "%0.*s, %02lu%s%02lu ",
  192.             strlen(PCHAR(*DaysOfWeek))/7, PSZ(*DaysOfWeek) + Dow*(strlen(PCHAR(*DaysOfWeek))/7),
  193.             Month, CountryInfo.szDateSeparator, Day ) ;
  194.          break ;
  195.  
  196.    } /* endswitch */
  197.  
  198.    if ( CountryInfo.fsTimeFmt ) {
  199.       if ( ShowSeconds )
  200.          sprintf ( Text+strlen(Text), "%02lu%s%02lu%s%02lu",
  201.              Hour, CountryInfo.szTimeSeparator, Minute, CountryInfo.szTimeSeparator, Second ) ;
  202.       else
  203.          sprintf ( Text+strlen(Text), "%02lu%s%02lu",
  204.              Hour, CountryInfo.szTimeSeparator, Minute ) ;
  205.    } else {
  206.       PCHAR AmPm ;
  207.       if ( Hour ) {
  208.          if ( Hour < 12 ) {
  209.             AmPm = szAm ;
  210.          } else if ( Hour == 12 ) {
  211.             if ( Minute )
  212.                AmPm = szPm ;
  213.             else
  214.                AmPm = szAm ;
  215.          } else if ( Hour > 12 ) {
  216.             Hour -= 12 ;
  217.             AmPm = szPm ;
  218.          } /* endif */
  219.       } else {
  220.          Hour = 12 ;
  221.          if ( Minute )
  222.             AmPm = szAm ;
  223.          else
  224.             AmPm = szPm ;
  225.       } /* endif */
  226.       if ( ShowSeconds )
  227.          sprintf ( Text+strlen(Text), "%02lu%s%02lu%s%02lu%s",
  228.              Hour, CountryInfo.szTimeSeparator, Minute, CountryInfo.szTimeSeparator, Second, AmPm ) ;
  229.       else
  230.          sprintf ( Text+strlen(Text), "%02lu%s%02lu%s",
  231.              Hour, CountryInfo.szTimeSeparator, Minute, AmPm ) ;
  232.    } /* endif */
  233.  
  234.    DdeUpdate ( Text ) ;
  235. }
  236.  
  237.  
  238. void Clock::FormatLine ( char *Buffer, int MaxWidth ) {
  239.  
  240.    // Get the left and right texts for the line.
  241.    char Label[100], Text[100] ;
  242.    FormatText ( Label, Text, QueryValue() ) ;
  243.  
  244.    // Format the line.
  245.    sprintf ( Buffer+strlen(Buffer), "%*s%s%*s", 
  246.       (MaxWidth-strlen(Text))/2, "", Text, 
  247.       MaxWidth-strlen(Text)-(MaxWidth-strlen(Text))/2, "" ) ;
  248.    strcat ( Buffer, "\r\n" ) ;
  249. }
  250.  
  251.  
  252. void Clock::Repaint ( HPS hPS, RECTL &Rectangle,
  253.    COLOR TextColor, COLOR BackColor, BOOL Mandatory ) {
  254.  
  255.    ULONG Time = NewValue ( ) ;
  256.    if ( Mandatory || ( Time != Value ) ) {
  257.       char Label[100], Text [100] ;
  258.       FormatText ( Label, Text, Time ) ;
  259.       WinDrawText ( hPS, strlen(Text), PSZ(Text), &Rectangle,
  260.          TextColor, BackColor, DT_CENTER | DT_BOTTOM | DT_ERASERECT ) ;
  261.       Value = Time ;
  262.    } /* endif */
  263. }
  264.  
  265.  
  266. int ElapsedTime::Measure ( HPS hPS, RECTL &Rectangle ) {
  267.    int Result ;
  268.    char Text [100] ;
  269.    Result = sprintf ( Text, "%s XX %s, XX:XX%s", QueryCurrentLabel(), PSZ(*Days), ShowSeconds?":XX":"" ) ;
  270.    WinQueryWindowRect ( HWND_DESKTOP, &Rectangle ) ;
  271.    WinDrawText ( hPS, strlen(Text), PSZ(Text), &Rectangle, 0, 0, DT_LEFT | DT_BOTTOM | DT_QUERYEXTENT ) ;
  272.    return ( Result ) ;
  273. }
  274.  
  275.  
  276. ULONG ElapsedTime::NewValue ( void ) {
  277.    ULONG Milliseconds ;
  278.    DosQuerySysInfo ( QSV_MS_COUNT, QSV_MS_COUNT, &Milliseconds, sizeof(Milliseconds) ) ;
  279.    return ( Milliseconds / 1000 ) ;
  280. }
  281.  
  282.  
  283. void ElapsedTime::FormatText ( char *Label, char *Text, ULONG Time ) {
  284.  
  285.    strcpy ( Label, CurrentLabel ) ;
  286.  
  287.    *Text = 0 ;
  288.  
  289.    ULONG NumberOfDays = Time / ( 60 * 60 * 24 ) ;
  290.    Time -= NumberOfDays * 60 * 60 * 24 ;
  291.    ULONG Hours   = Time / ( 60 * 60 ) ;
  292.    Time -= Hours * 60 * 60 ;
  293.    ULONG Minutes = Time / 60 ;
  294.    ULONG Seconds = Time % 60 ;
  295.  
  296.    if ( NumberOfDays ) {
  297.       sprintf ( Text, "%lu %s, ",
  298.          NumberOfDays, NumberOfDays > 1 ? PSZ(*Days) : PSZ(*Day) ) ;
  299.    } /* endif */
  300.  
  301.    if ( ShowSeconds )
  302.       sprintf ( Text+strlen(Text), "%lu%s%02lu%s%02lu",
  303.          Hours, CountryInfo.szTimeSeparator, Minutes,
  304.          CountryInfo.szTimeSeparator, Seconds ) ;
  305.    else
  306.       sprintf ( Text+strlen(Text), "%lu%s%02lu",
  307.          Hours, CountryInfo.szTimeSeparator, Minutes ) ;
  308.  
  309.    DdeUpdate ( Text ) ;
  310. }
  311.  
  312. void ElapsedTime::Repaint ( HPS hPS, RECTL &Rectangle,
  313.    COLOR TextColor, COLOR BackColor, BOOL Mandatory ) {
  314.  
  315.    ULONG Time = NewValue ( ) ;
  316.    if ( Mandatory || ( Time != Value ) ) {
  317.       char Label[100], Text[100] ;
  318.       FormatText ( Label, Text, Time ) ;
  319.       Paint ( hPS, Rectangle, TextColor, BackColor, Label, Text, Time ) ;
  320.    } /* endif */
  321. }
  322.  
  323.  
  324. int MemoryFree::Measure ( HPS hPS, RECTL &Rectangle ) {
  325.    int Result ;
  326.    char Text [100] ;
  327.    if ( ShowK != SHOWK_NEVER ) {
  328.       Result = sprintf ( Text, "%s 123,456K", QueryCurrentLabel() ) ;
  329.    } else {
  330.       Result = sprintf ( Text, "%s 123,456,789K", QueryCurrentLabel() ) ;
  331.    } /* endif */
  332.    WinQueryWindowRect ( HWND_DESKTOP, &Rectangle ) ;
  333.    WinDrawText ( hPS, strlen(Text), PSZ(Text), &Rectangle, 0, 0, DT_LEFT | DT_BOTTOM | DT_QUERYEXTENT ) ;
  334.    return ( Result ) ;
  335. }
  336.  
  337.  
  338. ULONG MemoryFree::NewValue ( void ) {
  339.    APIRET16 APIENTRY16 Dos16MemAvail ( PULONG pulAvailMem ) ;
  340.    ULONG Value ;
  341.    Dos16MemAvail ( &Value ) ;
  342.    return ( Value ) ;
  343. }
  344.  
  345.  
  346. void MemoryFree::FormatText ( char *Label, char *Text, ULONG Value ) {
  347.    strcpy ( Label, CurrentLabel ) ;
  348.    FormatValue ( Value, Text, CountryInfo, ShowK ) ;
  349.    DdeUpdate ( Text ) ;
  350. }
  351.  
  352.  
  353. void MemoryFree::Repaint ( HPS hPS, RECTL &Rectangle, 
  354.    COLOR TextColor, COLOR BackColor, BOOL Mandatory ) {
  355.  
  356.    ULONG Size = NewValue ( ) ;
  357.    if ( Mandatory || ( Size != Value ) ) {
  358.       char Label[100], Text [100] ;
  359.       FormatText ( Label, Text, Size ) ;
  360.       Paint ( hPS, Rectangle, TextColor, BackColor, Label, Text, Size ) ;
  361.    } /* endif */
  362. }
  363.  
  364.  
  365. int VirtualFree::Measure ( HPS hPS, RECTL &Rectangle ) {
  366.    int Result ;
  367.    char Text [100] ;
  368.    if ( ShowK != SHOWK_NEVER ) {
  369.       Result = sprintf ( Text, "%s 123,456K", QueryCurrentLabel() ) ;
  370.    } else {
  371.       Result = sprintf ( Text, "%s 123,456,789K", QueryCurrentLabel() ) ;
  372.    } /* endif */
  373.    WinQueryWindowRect ( HWND_DESKTOP, &Rectangle ) ;
  374.    WinDrawText ( hPS, strlen(Text), PSZ(Text), &Rectangle, 0, 0, DT_LEFT | DT_BOTTOM | DT_QUERYEXTENT ) ;
  375.    return ( Result ) ;
  376. }
  377.  
  378.  
  379. ULONG VirtualFree::NewValue ( void ) {
  380.    ULONG Space ;
  381.    DosQuerySysInfo ( QSV_TOTAVAILMEM, QSV_TOTAVAILMEM, &Space, sizeof(Space) ) ;
  382.    return ( Space ) ;
  383. }
  384.  
  385.  
  386. void VirtualFree::FormatText ( char *Label, char *Text, ULONG Value ) {
  387.  
  388.    strcpy ( Label, CurrentLabel ) ;
  389.  
  390.    FormatValue ( Value, Text, CountryInfo, ShowK ) ;
  391.  
  392.    DdeUpdate ( Text ) ;
  393. }
  394.  
  395.  
  396. void VirtualFree::Repaint ( HPS hPS, RECTL &Rectangle,
  397.    COLOR TextColor, COLOR BackColor, BOOL Mandatory ) {
  398.  
  399.    ULONG Size = NewValue ( ) ;
  400.    if ( Mandatory || ( Size != Value ) ) {
  401.       char Label[100], Text [100] ;
  402.       FormatText ( Label, Text, Size ) ;
  403.       Paint ( hPS, Rectangle, TextColor, BackColor, Label, Text, Size ) ;
  404.    } /* endif */
  405. }
  406.  
  407.  
  408. int SwapSize::Measure ( HPS hPS, RECTL &Rectangle ) {
  409.    int Result ;
  410.    char Text [100] ;
  411.    if ( ShowK != SHOWK_NEVER ) {
  412.       Result = sprintf ( Text, "%s 123,456K", QueryCurrentLabel() ) ;
  413.    } else {
  414.       Result = sprintf ( Text, "%s 123,456,789K", QueryCurrentLabel() ) ;
  415.    } /* endif */
  416.    WinQueryWindowRect ( HWND_DESKTOP, &Rectangle ) ;
  417.    WinDrawText ( hPS, strlen(Text), PSZ(Text), &Rectangle, 0, 0, DT_LEFT | DT_BOTTOM | DT_QUERYEXTENT ) ;
  418.    return ( Result ) ;
  419. }
  420.  
  421.  
  422. ULONG SwapSize::NewValue ( void ) {
  423.  
  424.    char Path [_MAX_PATH+1] ;
  425.    strcpy ( Path, (PCHAR)SwapPath ) ;
  426.  
  427.    if ( Path[strlen(Path)-1] != '\\' )
  428.       strcat ( Path, "\\" ) ;
  429.  
  430.    strcat ( Path, "SWAPPER.DAT" ) ;
  431.  
  432.    ULONG SwapSize = 0 ;
  433.    FILESTATUS3 Status ;
  434.    if ( DosQueryPathInfo ( (PSZ)Path, FIL_STANDARD, &Status, sizeof(Status) ) == 0 ) 
  435.       SwapSize = Status.cbFileAlloc ;
  436.  
  437.    return ( SwapSize ) ;
  438. }
  439.  
  440.  
  441. void SwapSize::FormatText ( char *Label, char *Text, ULONG Value ) {
  442.  
  443.    strcpy ( Label, CurrentLabel ) ;
  444.  
  445.    FormatValue ( Value, Text, CountryInfo, ShowK ) ;
  446.  
  447.    DdeUpdate ( Text ) ;
  448. }
  449.  
  450.  
  451. void SwapSize::Repaint ( HPS hPS, RECTL &Rectangle,
  452.    COLOR TextColor, COLOR BackColor, BOOL Mandatory ) {
  453.  
  454.    ULONG Size = NewValue ( ) ;
  455.    if ( Mandatory || ( Size != Value ) ) {
  456.       char Label[100], Text [100] ;
  457.       FormatText ( Label, Text, Size ) ;
  458.       Paint ( hPS, Rectangle, TextColor, BackColor, Label, Text, Size ) ;
  459.    } /* endif */
  460. }
  461.  
  462.  
  463. int SwapFree::Measure ( HPS hPS, RECTL &Rectangle ) {
  464.    int Result ;
  465.    char Text [100] ;
  466.    if ( ShowK != SHOWK_NEVER ) {
  467.       Result = sprintf ( Text, "%s 123,456K", QueryCurrentLabel() ) ;
  468.    } else {
  469.       Result = sprintf ( Text, "%s 123,456,789K", QueryCurrentLabel() ) ;
  470.    } /* endif */
  471.    WinQueryWindowRect ( HWND_DESKTOP, &Rectangle ) ;
  472.    WinDrawText ( hPS, strlen(Text), PSZ(Text), &Rectangle, 0, 0, DT_LEFT | DT_BOTTOM | DT_QUERYEXTENT ) ;
  473.    return ( Result ) ;
  474. }
  475.  
  476.  
  477. ULONG SwapFree::NewValue ( void ) {
  478.  
  479.    DosError ( FERR_DISABLEHARDERR ) ;
  480.    FSALLOCATE Allocation ;
  481.    DosQueryFSInfo ( SwapPath[0]-'A'+1, FSIL_ALLOC, PBYTE(&Allocation), sizeof(Allocation) ) ;
  482.    DosError ( FERR_ENABLEHARDERR ) ;
  483.  
  484.    ULONG SwapFree = Allocation.cUnitAvail*Allocation.cSectorUnit*Allocation.cbSector ;
  485.  
  486.    if ( SwapFree < ULONG(MinFree*1024) )
  487.       return ( 0 ) ;
  488.    else
  489.       return ( ULONG ( ( SwapFree - ULONG(MinFree*1024) ) / (1024*1024) ) * (1024*1024) ) ;
  490. }
  491.  
  492.  
  493. void SwapFree::FormatText ( char *Label, char *Text, ULONG Value ) {
  494.  
  495.    strcpy ( Label, CurrentLabel ) ;
  496.  
  497.    FormatValue ( Value, Text, CountryInfo, ShowK ) ;
  498.  
  499.    DdeUpdate ( Text ) ;
  500. }
  501.  
  502.  
  503. void SwapFree::Repaint ( HPS hPS, RECTL &Rectangle,
  504.    COLOR TextColor, COLOR BackColor, BOOL Mandatory ) {
  505.  
  506.    ULONG Size = NewValue ( ) ;
  507.    if ( Mandatory || ( Size != Value ) ) {
  508.       char Label[100], Text [100] ;
  509.       FormatText ( Label, Text, Size ) ;
  510.       Paint ( hPS, Rectangle, TextColor, BackColor, Label, Text, Size ) ;
  511.    } /* endif */
  512. }
  513.  
  514.  
  515. int SpoolSize::Measure ( HPS hPS, RECTL &Rectangle ) {
  516.    int Result ;
  517.    char Text [100] ;
  518.    if ( ShowK != SHOWK_NEVER ) {
  519.       Result = sprintf ( Text, "%s 123,456K", QueryCurrentLabel() ) ;
  520.    } else {
  521.       Result = sprintf ( Text, "%s 123,456,789K", QueryCurrentLabel() ) ;
  522.    } /* endif */
  523.    WinQueryWindowRect ( HWND_DESKTOP, &Rectangle ) ;
  524.    WinDrawText ( hPS, strlen(Text), PSZ(Text), &Rectangle, 0, 0, DT_LEFT | DT_BOTTOM | DT_QUERYEXTENT ) ;
  525.    return ( Result ) ;
  526. }
  527.  
  528.  
  529. ULONG SpoolSize::NewValue ( void ) {
  530.  
  531.    ULONG PathSize ;
  532.    DosQuerySysInfo ( QSV_MAX_PATH_LENGTH, QSV_MAX_PATH_LENGTH, &PathSize, sizeof(PathSize) ) ;
  533.  
  534.    PBYTE Path = PBYTE ( malloc ( size_t(PathSize) ) ) ;
  535.    if ( Path == NULL ) 
  536.       return ( 0 ) ;
  537.  
  538.    PFILEFINDBUF3 Found = PFILEFINDBUF3 ( malloc ( size_t( PathSize + sizeof(FILEFINDBUF3) ) ) ) ;
  539.    if ( Found == NULL ) {
  540.       free ( Path ) ;
  541.       return ( 0 ) ;
  542.    } /* endif */
  543.  
  544.    strcpy ( (PCHAR)Path, (PCHAR)SpoolPath ) ;
  545.    strcat ( (PCHAR)Path, "\\*.*" ) ;
  546.  
  547.    HDIR hDir = (HDIR) HDIR_CREATE ;
  548.    ULONG Count = 1 ;
  549.    ULONG TotalSize = 0 ;
  550.  
  551.    if ( !DosFindFirst2 ( Path, &hDir,
  552.       FILE_NORMAL | FILE_READONLY | FILE_DIRECTORY | FILE_ARCHIVED,
  553.       Found, PathSize+sizeof(FILEFINDBUF3), &Count, FIL_STANDARD ) ) {
  554.  
  555.       do {
  556.  
  557.          if ( !strcmp ( (PCHAR)Found->achName, "." ) OR !strcmp ( (PCHAR)Found->achName, ".." ) )
  558.             continue ;
  559.  
  560.          if ( Found->attrFile & FILE_DIRECTORY ) {
  561.  
  562.             HDIR hDir2 = (HDIR) HDIR_CREATE ;
  563.  
  564.             strcpy ( (PCHAR)Path, (PCHAR)SpoolPath ) ;
  565.             strcat ( (PCHAR)Path, "\\" ) ;
  566.             strcat ( (PCHAR)Path, (PCHAR)Found->achName ) ;
  567.             strcat ( (PCHAR)Path, "\\*.*" ) ;
  568.  
  569.             ULONG Count2 = 1 ;
  570.             if ( !DosFindFirst2 ( Path, &hDir2,
  571.                FILE_NORMAL | FILE_READONLY | FILE_ARCHIVED,
  572.                Found, PathSize+sizeof(FILEFINDBUF3), &Count2, FIL_STANDARD ) ) {
  573.                do {
  574.                   TotalSize += Found->cbFileAlloc ;
  575.                } while ( !DosFindNext ( hDir2, Found, PathSize+sizeof(FILEFINDBUF3), &Count2 ) ) ;
  576.                DosFindClose ( hDir2 ) ;
  577.             } /* endif */
  578.          } else {
  579.             TotalSize += Found->cbFileAlloc ;
  580.          } /* endif */
  581.       } while ( !DosFindNext ( hDir, Found, PathSize+sizeof(FILEFINDBUF3), &Count ) ) ;
  582.  
  583.       DosFindClose ( hDir ) ;
  584.  
  585.    } /* enddo */
  586.  
  587.    free ( Path ) ;
  588.    free ( Found ) ;
  589.  
  590.    return ( TotalSize ) ;
  591. }
  592.  
  593.  
  594. void SpoolSize::FormatText ( char *Label, char *Text, ULONG Value ) {
  595.  
  596.    strcpy ( Label, CurrentLabel ) ;
  597.  
  598.    FormatValue ( Value, Text, CountryInfo, ShowK ) ;
  599.  
  600.    DdeUpdate ( Text ) ;
  601. }
  602.  
  603.  
  604. void SpoolSize::Repaint ( HPS hPS, RECTL &Rectangle,
  605.    COLOR TextColor, COLOR BackColor, BOOL Mandatory ) {
  606.  
  607.    ULONG Size = NewValue ( ) ;
  608.    if ( Mandatory || ( Size != Value ) ) {
  609.       char Label[100], Text [100] ;
  610.       FormatText ( Label, Text, Size ) ;
  611.       Paint ( hPS, Rectangle, TextColor, BackColor, Label, Text, Size ) ;
  612.    } /* endif */
  613. }
  614.  
  615.  
  616. int CpuLoad::Measure ( HPS hPS, RECTL &Rectangle ) {
  617.    int Result ;
  618.    char Text [100] ;
  619.    Result = sprintf ( Text, "%s 100%", QueryCurrentLabel() ) ;
  620.    WinQueryWindowRect ( HWND_DESKTOP, &Rectangle ) ;
  621.    WinDrawText ( hPS, strlen(Text), PSZ(Text), &Rectangle, 0, 0, DT_LEFT | DT_BOTTOM | DT_QUERYEXTENT ) ;
  622.    return ( Result ) ;
  623. }
  624.  
  625.  
  626. ULONG CpuLoad::NewValue ( void ) {
  627.    MaxCount = (ULONG) max ( MaxCount, *IdleCount ) ;
  628.    ULONG Load = ( ( MaxCount - *IdleCount ) * 100 ) / MaxCount ;
  629.    return ( Load ) ;
  630. }
  631.  
  632.  
  633. void CpuLoad::FormatText ( char *Label, char *Text, ULONG Value ) {
  634.  
  635.    strcpy ( Label, CurrentLabel ) ;
  636.  
  637.    sprintf ( Text, "%lu%%", Value ) ;
  638.  
  639.    DdeUpdate ( Text ) ;
  640. }
  641.  
  642.  
  643. void CpuLoad::Repaint ( HPS hPS, RECTL &Rectangle, 
  644.    COLOR TextColor, COLOR BackColor, BOOL Mandatory ) {
  645.  
  646.    ULONG Load = NewValue ( ) ;
  647.    if ( Mandatory || ( Load != Value ) ) {
  648.       char Label[100], Text [100] ;
  649.       FormatText ( Label, Text, Load ) ;
  650.       Paint ( hPS, Rectangle, TextColor, BackColor, Label, Text, Load ) ;
  651.    } /* endif */
  652. }
  653.  
  654.  
  655. int TaskCount::Measure ( HPS hPS, RECTL &Rectangle ) {
  656.    int Result ;
  657.    char Text [100] ;
  658.    Result = sprintf ( Text, "%s 999 ", QueryCurrentLabel() ) ;
  659.    WinQueryWindowRect ( HWND_DESKTOP, &Rectangle ) ;
  660.    WinDrawText ( hPS, strlen(Text), PSZ(Text), &Rectangle, 0, 0, DT_LEFT | DT_BOTTOM | DT_QUERYEXTENT ) ;
  661.    return ( Result ) ;
  662. }
  663.  
  664.  
  665. ULONG TaskCount::NewValue ( void ) {
  666.    return ( WinQuerySwitchList ( Anchor, PSWBLOCK(NULL), 0 ) ) ;
  667. }
  668.  
  669.  
  670. void TaskCount::FormatText ( char *Label, char *Text, ULONG Value ) {
  671.  
  672.    strcpy ( Label, CurrentLabel ) ;
  673.  
  674.    sprintf ( Text, "%lu ", Value ) ;
  675.  
  676.    DdeUpdate ( Text ) ;
  677. }
  678.  
  679.  
  680. void TaskCount::Repaint ( HPS hPS, RECTL &Rectangle,
  681.    COLOR TextColor, COLOR BackColor, BOOL Mandatory ) {
  682.  
  683.    ULONG Count = NewValue ( ) ;
  684.    if ( Mandatory || ( Count != Value ) ) {
  685.       char Label[100], Text [100] ;
  686.       FormatText ( Label, Text, Count ) ;
  687.       Paint ( hPS, Rectangle, TextColor, BackColor, Label, Text, Count ) ;
  688.    } /* endif */
  689. }
  690.  
  691.  
  692. int DriveFree::Measure ( HPS hPS, RECTL &Rectangle ) {
  693.    int Result ;
  694.    char Text [100] ;
  695.    if ( ShowFileSystemName && *FileSystem ) {
  696.       if ( ShowDiskLabel && *DiskLabel ) {
  697.          if ( ShowK != SHOWK_NEVER ) {
  698.             Result = sprintf ( Text, "%s (%s,%s) 1,234,567K", QueryCurrentLabel(), DiskLabel, FileSystem ) ;
  699.          } else {
  700.             Result = sprintf ( Text, "%s (%s,%s) 1,234,567,890K", QueryCurrentLabel(), DiskLabel, FileSystem ) ;
  701.          } /* endif */
  702.       } else {
  703.          if ( ShowK != SHOWK_NEVER ) {
  704.             Result = sprintf ( Text, "%s (%s) 1,234,567K", QueryCurrentLabel(), FileSystem ) ;
  705.          } else {
  706.             Result = sprintf ( Text, "%s (%s) 1,234,567,890K", QueryCurrentLabel(), FileSystem ) ;
  707.          } /* endif */
  708.       } /* endif */
  709.    } else {
  710.       if ( ShowDiskLabel && *DiskLabel ) {
  711.          if ( ShowK != SHOWK_NEVER ) {
  712.             Result = sprintf ( Text, "%s (%s) 1,234,567K", QueryCurrentLabel(), DiskLabel ) ;
  713.          } else {
  714.             Result = sprintf ( Text, "%s (%s) 1,234,567,890K", QueryCurrentLabel(), DiskLabel ) ;
  715.          } /* endif */
  716.       } else {
  717.          if ( ShowK != SHOWK_NEVER ) {
  718.             Result = sprintf ( Text, "%s 1,234,567K", QueryCurrentLabel() ) ;
  719.          } else {
  720.             Result = sprintf ( Text, "%s 1,234,567,890K", QueryCurrentLabel() ) ;
  721.          } /* endif */
  722.       } /* endif */
  723.    } /* endif */
  724.    WinQueryWindowRect ( HWND_DESKTOP, &Rectangle ) ;
  725.    WinDrawText ( hPS, strlen(Text), PSZ(Text), &Rectangle, 0, 0, DT_LEFT | DT_BOTTOM | DT_QUERYEXTENT ) ;
  726.    return ( Result ) ;
  727. }
  728.  
  729.  
  730. ULONG DriveFree::NewValue ( void ) {
  731.  
  732.    if ( Error ) 
  733.       return ( 0 ) ;
  734.  
  735.    DosError ( FERR_DISABLEHARDERR ) ;
  736.  
  737.    FSALLOCATE Allocation ;
  738.    APIRET Status = DosQueryFSInfo ( DriveNumber, FSIL_ALLOC, (PBYTE)&Allocation, sizeof(Allocation) ) ;
  739.  
  740.    DosError ( FERR_ENABLEHARDERR ) ;
  741.  
  742.    if ( Status ) {
  743.       Error = TRUE ;
  744.       return ( 0 ) ;
  745.    } /* endif */
  746.  
  747.    return ( Allocation.cUnitAvail*Allocation.cSectorUnit*Allocation.cbSector ) ;
  748. }
  749.  
  750.  
  751. void DriveFree::FormatText ( char *Label, char *Text, ULONG Value ) {
  752.  
  753.    if ( ShowFileSystemName && *FileSystem ) {
  754.       if ( ShowDiskLabel && *DiskLabel ) {
  755.          sprintf ( Label, "%s (%s,%s)", QueryCurrentLabel(), DiskLabel, FileSystem ) ;
  756.       } else {
  757.          sprintf ( Label, "%s (%s)", QueryCurrentLabel(), FileSystem ) ;
  758.       } /* endif */
  759.    } else {
  760.       if ( ShowDiskLabel && *DiskLabel ) {
  761.          sprintf ( Label, "%s (%s)", QueryCurrentLabel(), DiskLabel ) ;
  762.       } else {
  763.          sprintf ( Label, "%s", QueryCurrentLabel() ) ;
  764.       } /* endif */
  765.    } /* endif */
  766.  
  767.    if ( Error )
  768.       strcpy ( Text, PCHAR(*DriveError) ) ;
  769.    else
  770.       FormatValue ( Value, Text, CountryInfo, ShowK ) ;
  771.  
  772.    DdeUpdate ( Text ) ;
  773. }
  774.  
  775.  
  776. void DriveFree::Repaint ( HPS hPS, RECTL &Rectangle,
  777.    COLOR TextColor, COLOR BackColor, BOOL Mandatory ) {
  778.  
  779.    ULONG Size = NewValue ( ) ;
  780.    if ( Mandatory || ( Size != Value ) ) {
  781.       char Label[100], Text [100] ;
  782.       FormatText ( Label, Text, Size ) ;
  783.       Paint ( hPS, Rectangle, TextColor, BackColor, Label, Text, Size ) ;
  784.    } /* endif */
  785. }
  786.  
  787.  
  788. int TotalFree::Measure ( HPS hPS, RECTL &Rectangle ) {
  789.    int Result ;
  790.    char Text [100] ;
  791.    if ( ShowK != SHOWK_NEVER ) {
  792.       Result = sprintf ( Text, "%s 0,123,456K", QueryCurrentLabel() ) ;
  793.    } else {
  794.       Result = sprintf ( Text, "%s 0,123,456,789K", QueryCurrentLabel() ) ;
  795.    } /* endif */
  796.    WinQueryWindowRect ( HWND_DESKTOP, &Rectangle ) ;
  797.    WinDrawText ( hPS, strlen(Text), PSZ(Text), &Rectangle, 0, 0, DT_LEFT | DT_BOTTOM | DT_QUERYEXTENT ) ;
  798.    return ( Result ) ;
  799. }
  800.  
  801.  
  802. ULONG TotalFree::NewValue ( void ) {
  803.  
  804.    ULONG Free = 0 ;
  805.    ULONG Mask = Drives >> 2 ;
  806.  
  807.    for ( int Drive=3; Drive<=26; Drive++ ) {
  808.       if ( Mask & 1 ) {
  809.  
  810.          DosError ( FERR_DISABLEHARDERR ) ;
  811.  
  812.          FSALLOCATE Allocation ;
  813.          APIRET Status = DosQueryFSInfo ( Drive, FSIL_ALLOC, (PBYTE)&Allocation, sizeof(Allocation) ) ;
  814.  
  815.          DosError ( FERR_ENABLEHARDERR ) ;
  816.  
  817.          if ( Status )
  818.             Drives &= ~ ( 1 << (Drive-1) ) ;
  819.          else
  820.             Free += Allocation.cUnitAvail*Allocation.cSectorUnit*(Allocation.cbSector/256) ;
  821.       } /* endif */
  822.       Mask >>= 1 ;
  823.  
  824.    } /* endfor */
  825.  
  826.    return ( Free ) ;
  827. }
  828.  
  829.  
  830. void TotalFree::FormatText ( char *Label, char *Text, ULONG Value ) {
  831.  
  832.    strcpy ( Label, CurrentLabel ) ;
  833.  
  834.    FormatValue ( Value, Text, CountryInfo, ShowK, 256 ) ;
  835.  
  836.    DdeUpdate ( Text ) ;
  837. }
  838.  
  839.  
  840. void TotalFree::Repaint ( HPS hPS, RECTL &Rectangle,
  841.    COLOR TextColor, COLOR BackColor, BOOL Mandatory ) {
  842.  
  843.    ULONG Size = NewValue ( ) ;
  844.    if ( Mandatory || ( Size != Value ) ) {
  845.       char Label[100], Text [100] ;
  846.       FormatText ( Label, Text, Size ) ;
  847.       Paint ( hPS, Rectangle, TextColor, BackColor, Label, Text, Size ) ;
  848.    } /* endif */
  849. }
  850.  
  851.  
  852. int SwapSlack::Measure ( HPS hPS, RECTL &Rectangle ) {
  853.    int Result ;
  854.    char Text [100] ;
  855.    if ( ShowK != SHOWK_NEVER ) {
  856.       Result = sprintf ( Text, "%s 123,456K", QueryCurrentLabel() ) ;
  857.    } else {
  858.       Result = sprintf ( Text, "%s 123,456,789K", QueryCurrentLabel() ) ;
  859.    } /* endif */
  860.    WinQueryWindowRect ( HWND_DESKTOP, &Rectangle ) ;
  861.    WinDrawText ( hPS, strlen(Text), PSZ(Text), &Rectangle, 0, 0, DT_LEFT | DT_BOTTOM | DT_QUERYEXTENT ) ;
  862.    return ( Result ) ;
  863. }
  864.  
  865. ULONG SwapSlack::NewValue ( void ) {
  866.    LONG Slack = pVirtualFree->QueryFlag() ? pVirtualFree->QueryValue() : pVirtualFree->NewValue() ;
  867.    Slack -= pSwapFree->QueryFlag() ? pSwapFree->QueryValue() : pSwapFree->NewValue() ;
  868.    Slack -= pMemFree->QueryFlag() ? pMemFree->QueryValue() : pMemFree->NewValue() ;
  869.    return ( ULONG ( max ( 0, Slack ) ) ) ;
  870. }
  871.  
  872. void SwapSlack::FormatText ( char *Label, char *Text, ULONG Value ) {
  873.  
  874.    strcpy ( Label, CurrentLabel ) ;
  875.  
  876.    FormatValue ( Value, Text, CountryInfo, ShowK ) ;
  877.  
  878.    DdeUpdate ( Text ) ;
  879. }
  880.  
  881. void SwapSlack::Repaint ( HPS hPS, RECTL &Rectangle,
  882.    COLOR TextColor, COLOR BackColor, BOOL Mandatory ) {
  883.  
  884.    ULONG Size = NewValue ( ) ;
  885.    if ( Mandatory || ( Size != Value ) ) {
  886.       char Label[100], Text[100] ;
  887.       FormatText ( Label, Text, Size ) ;
  888.       Paint ( hPS, Rectangle, TextColor, BackColor, Label, Text, Size ) ;
  889.    } /* endif */
  890. }
  891.  
  892.  
  893. int ProcessCount::Measure ( HPS hPS, RECTL &Rectangle ) {
  894.    int Result ;
  895.    char Text [100] ;
  896.    Result = sprintf ( Text, "%s 123 ", QueryCurrentLabel() ) ;
  897.    WinQueryWindowRect ( HWND_DESKTOP, &Rectangle ) ;
  898.    WinDrawText ( hPS, strlen(Text), PSZ(Text), &Rectangle, 0, 0, DT_LEFT | DT_BOTTOM | DT_QUERYEXTENT ) ;
  899.    return ( Result ) ;
  900. }
  901.  
  902. ULONG ProcessCount::NewValue ( void ) {
  903.  
  904.    if ( DosQProcStatus ( DQPS_Buffer, 0xFFFF ) ) 
  905.       return ( 0 ) ;
  906.  
  907.    qsPrec_s *pProcRecord = ((qsPtrRec_s*)DQPS_Buffer)->pProcRec ;
  908.    int ProcessCount = 0 ;
  909.    while ( pProcRecord->RecType == 1 ) {
  910.       int Size = sizeof(qsPrec_s) ;
  911.       Size += pProcRecord->cTCB * sizeof(qsTrec_s) ;
  912.       Size += pProcRecord->c16Sem * sizeof(short) ;
  913.       Size += pProcRecord->cLib * sizeof(short) ;
  914.       Size += pProcRecord->cShrMem * sizeof(short) ;
  915.       pProcRecord = (qsPrec_s*) ( (char*)pProcRecord + Size ) ;
  916.       ProcessCount ++ ;
  917.    } /* endwhile */
  918.    return ( ProcessCount ) ;
  919. }
  920.  
  921. void ProcessCount::FormatText ( char *Label, char *Text, ULONG Value ) {
  922.    strcpy ( Label, CurrentLabel ) ;
  923.    sprintf ( Text, "%lu ", Value ) ;
  924.    DdeUpdate ( Text ) ;
  925. }
  926.  
  927. void ProcessCount::Repaint ( HPS hPS, RECTL &Rectangle, COLOR TextColor, COLOR BackColor, BOOL Mandatory ) {
  928.    ULONG Size = NewValue ( ) ;
  929.    if ( Mandatory || ( Size != Value ) ) {
  930.       char Label[100], Text[100] ;
  931.       FormatText ( Label, Text, Size ) ;
  932.       Paint ( hPS, Rectangle, TextColor, BackColor, Label, Text, Size ) ;
  933.    } /* endif */
  934. }
  935.  
  936.  
  937. int ThreadCount::Measure ( HPS hPS, RECTL &Rectangle ) {
  938.    int Result ;
  939.    char Text [100] ;
  940.    Result = sprintf ( Text, "%s 123 ", QueryCurrentLabel() ) ;
  941.    WinQueryWindowRect ( HWND_DESKTOP, &Rectangle ) ;
  942.    WinDrawText ( hPS, strlen(Text), PSZ(Text), &Rectangle, 0, 0, DT_LEFT | DT_BOTTOM | DT_QUERYEXTENT ) ;
  943.    return ( Result ) ;
  944. }
  945.  
  946. ULONG ThreadCount::NewValue ( void ) {
  947.  
  948.    if ( DosQProcStatus ( DQPS_Buffer, 0xFFFF ) )
  949.       return ( 0 ) ;
  950.  
  951.    return ( ((qsPtrRec_s*)DQPS_Buffer)->pGlobalRec->cThrds ) ;
  952. }
  953.  
  954. void ThreadCount::FormatText ( char *Label, char *Text, ULONG Value ) {
  955.    strcpy ( Label, CurrentLabel ) ;
  956.    sprintf ( Text, "%lu ", Value ) ;
  957.    DdeUpdate ( Text ) ;
  958. }
  959.  
  960. void ThreadCount::Repaint ( HPS hPS, RECTL &Rectangle, COLOR TextColor, COLOR BackColor, BOOL Mandatory ) {
  961.    ULONG Size = NewValue ( ) ;
  962.    if ( Mandatory || ( Size != Value ) ) {
  963.       char Label[100], Text[100] ;
  964.       FormatText ( Label, Text, Size ) ;
  965.       Paint ( hPS, Rectangle, TextColor, BackColor, Label, Text, Size ) ;
  966.    } /* endif */
  967. }
  968.  
  969.